withCriteria

Purpose

Allows inline execution of criteria with a closure. See the createCriteria method for reference.

Examples

def results = Book.withCriteria {
    def now = new Date()
    between('releaseDate', now-7, now)
    like('title', '%Groovy%')
}

Description

The withCriteria method allows the inline definition of Criteria. Arguments to the HibernateCriteriaBuilder can be passed as the first parameter:

def book = Book.withCriteria(uniqueResult:true) {
    def now = new Date()
    between('releaseDate', now-7, now)
    like('title', '%Groovy%')
}

Parameters: